﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChessSuite.Utilities.Common.Enumeations;

namespace ChessSuite.Utilities.Common.Moves
{
    public class PromotionMove :  Move
    {
        #region Constructors.
        public PromotionMove(int fileFrom, int rankFrom, int fileTo, int rankTo, PieceType promotionType)
            : base(fileFrom, rankFrom, fileFrom, rankTo)
        {
            ValidatePromotionType(promotionType);
            ValidateEndRank(rankTo);
            PromotionType = promotionType;
        }
        public PromotionMove(Position from, Position to, PieceType promotionType)
            : this(from.File, from.Rank, to.File, to.Rank, promotionType)
        {
        }
        #endregion

        #region Properties.
        public PieceType PromotionType { get; private set; }
        #endregion

        #region Validation.
        public static void ValidatePromotionType(PieceType promotionType)
        {
            if (promotionType == PieceType.Pawn || promotionType == PieceType.King)
                throw new ArgumentOutOfRangeException("promotionType", string.Format(Resources.PROMOTION_MOVE_EXCEPTION_INVALID_PROMOTION_TYPE_FORMAT, promotionType));
        }

        public static void ValidateEndRank(int rankTo)
        {
            if (rankTo != 0 && rankTo != 7)
                throw new ArgumentOutOfRangeException("rankTo", string.Format(Resources.PROMOTION_MOVE_EXCEPTION_INVALID_DESTINATION_RANK_FORMAT, rankTo));
        }
        #endregion
    }
}
